package com.kk;

import com.kk.filter.TokenAuthFilter;
import com.kk.util.redis.RedisUtils;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.web.filter.DelegatingFilterProxy;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@SpringBootApplication
public class RunApplication {
    public static void main(String[] args) {
        ApplicationContext applicationContext = SpringApplication.run(RunApplication.class, args);

    }

//    @Bean
//    public TokenAuthFilter getTokenAuthFilter() {
//        return new TokenAuthFilter();
//    }
    //注册filter
    @Bean
    public FilterRegistrationBean filterRegistrationBean() {
        FilterRegistrationBean registrationBean = new FilterRegistrationBean();
        TokenAuthFilter tokenAuthFilter = new TokenAuthFilter();
        registrationBean.setFilter(tokenAuthFilter);
        List<String> urlPatterns = new ArrayList<>();
        urlPatterns.add("/user/*");
        registrationBean.setUrlPatterns(urlPatterns);
        return registrationBean;
//        FilterRegistrationBean registration = new FilterRegistrationBean();
//        DelegatingFilterProxy httpBasicFilter = new DelegatingFilterProxy();
//        httpBasicFilter.setTargetFilterLifecycle(true);
//        httpBasicFilter.setTargetBeanName("tokenAuthFilter");
//        registration.setFilter(httpBasicFilter);
////        Map<String,String> m = new HashMap<>();
////        m.put("targetBeanName","tokenAuthFilter");
////        m.put("targetFilterLifecycle","true");
//        List<String> urlPatterns = new ArrayList<>();
//        urlPatterns.add("/user/*");
//        registration.setUrlPatterns(urlPatterns);
//
//        registration.setOrder(2);
//        return registration;

    }

}
